home *** CD-ROM | disk | FTP | other *** search
/ 500 MB Nyheder Direkte fra Internet 9 / 500 MB nyheder direkte fra internet CD 9.iso / start / zipped / win / progtool / run_app.cls < prev    next >
Text File  |  1996-01-03  |  3KB  |  107 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "CRunApp"
  6. Attribute VB_Creatable = True
  7. Attribute VB_Exposed = True
  8. Option Explicit
  9.   
  10.   Private Type STARTUPINFO
  11.      cb As Long
  12.      lpReserved As String
  13.      lpDesktop As String
  14.      lpTitle As String
  15.      dwX As Long
  16.      dwY As Long
  17.      dwXSize As Long
  18.      dwYSize As Long
  19.      dwXCountChars As Long
  20.      dwYCountChars As Long
  21.      dwFillAttribute As Long
  22.      dwFlags As Long
  23.      wShowWindow As Integer
  24.      cbReserved2 As Integer
  25.      lpReserved2 As Long
  26.      hStdInput As Long
  27.      hStdOutput As Long
  28.      hStdError As Long
  29.   End Type
  30.  
  31.   Private Type PROCESS_INFORMATION
  32.      hProcess As Long
  33.      hThread As Long
  34.      dwProcessID As Long
  35.      dwThreadID As Long
  36.   End Type
  37.  
  38.   Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
  39.      lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
  40.      lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
  41.      ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
  42.      ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
  43.      lpStartupInfo As STARTUPINFO, lpProcessInformation As _
  44.      PROCESS_INFORMATION) As Long
  45.   
  46.   Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
  47.      hHandle As Long, ByVal dwMilliseconds As Long) As Long
  48.  
  49.   Private Declare Function CloseHandle Lib "kernel32" (ByVal _
  50.      hObject As Long) As Long
  51.  
  52.   Private Const NORMAL_PRIORITY_CLASS = &H20&
  53.   Private Const INFINITE = -1&
  54.   
  55.   Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal _
  56.      dwAccess As Long, ByVal fInherit As Integer, ByVal hObject _
  57.      As Long) As Long
  58.  
  59.   Private Declare Function TerminateProcess Lib "kernel32" (ByVal _
  60.      hProcess As Long, ByVal uExitCode As Long) As Long
  61.  
  62.   Private Const SYNCHRONIZE = 1048576
  63.   
  64.   Private Const STARTF_USESHOWWINDOW = &H1
  65.   Private Const HIDEWIN = 0
  66.   Private Const NORMAL = 1
  67.   Private Const MINIMIZE = 2
  68.   
  69.   Private ProcessID As Long    'returned by CreateProcess
  70.   Private ThreadID As Long     'returned by CreateProcess
  71.  
  72.  
  73. Public Function Run(cmdline$, windowstate%) As Long
  74.        
  75.     Dim proc As PROCESS_INFORMATION
  76.     Dim start As STARTUPINFO
  77.     Dim temp As Long
  78.     
  79.  'Else Set Info Structure
  80.     start.cb = Len(start)
  81.     start.dwFlags = STARTF_USESHOWWINDOW
  82.     start.wShowWindow = windowstate%
  83.  'Run the application
  84.     temp& = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
  85.             NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
  86.     While temp& = 0
  87.         DoEvents
  88.         MsgBox "Doing Events"
  89.     Wend
  90.     ProcessID& = proc.hProcess
  91.     ThreadID& = proc.hThread
  92.     Run = ProcessID&
  93.         
  94. End Function
  95.  
  96.  
  97.  
  98. Public Sub Terminate()
  99.     
  100.     Dim temp As Long
  101.     temp& = TerminateProcess(ProcessID&, 0&)
  102.     temp& = CloseHandle(ThreadID&)
  103.     temp& = CloseHandle(ProcessID&)
  104.  
  105. End Sub
  106.  
  107.